//package com.tuo51;
//
//import fr.opensagres.poi.xwpf.converter.xhtml.XHTMLConverter;
//import fr.opensagres.poi.xwpf.converter.xhtml.XHTMLOptions;
//import org.apache.poi.hwpf.HWPFDocument;
//import org.apache.poi.hwpf.converter.WordToHtmlConverter;
//import org.apache.poi.hwpf.converter.WordToTextConverter;
//import org.apache.poi.openxml4j.util.ZipSecureFile;
//import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
//import org.apache.poi.xwpf.usermodel.XWPFDocument;
//
//import javax.xml.parsers.DocumentBuilderFactory;
//import javax.xml.parsers.ParserConfigurationException;
//import javax.xml.transform.OutputKeys;
//import javax.xml.transform.Transformer;
//import javax.xml.transform.TransformerException;
//import javax.xml.transform.TransformerFactory;
//import javax.xml.transform.dom.DOMSource;
//import javax.xml.transform.stream.StreamResult;
//import java.io.*;
//import java.net.URL;
//
//public class TestMain {
//
//    public static void main(String[] argv){
//        String html = null;
//        try {
////            html = docxToHtml("https://gxrd.oss-cn-shenzhen.aliyuncs.com/gxrd/docmoban/%E5%85%B3%E4%BA%8E%C3%97%C3%97%C3%97%E7%AD%89%E4%BB%BB%E5%85%8D%E8%81%8C%E7%9A%84%E9%80%9A%E7%9F%A5.docx");
////            html = docxToTxt("https://gxrd.oss-cn-shenzhen.aliyuncs.com/gxrd/process/269972030277812224/关于审议测试11121的报告审议意见.docx");
//            html = docxToHtml("https://gxrd.oss-cn-shenzhen.aliyuncs.com/gxrd/user/A9B934B833164BB8BB1DC8072776DB07/277052379180826624%E8%87%AA%E6%B2%BB%E5%8C%BA%E4%BA%BA%E6%B0%91%E6%94%BF%E5%BA%9C%E7%AD%94%E5%A4%8D.docx");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        System.out.println(html);
//    }
//    // docx转换为html
//    public static String docxToHtml(String url) throws IOException {
//        InputStream inputStream =   new URL(url).openStream();
//
//        ZipSecureFile.setMinInflateRatio(-1.0d);
//        XWPFDocument document = new XWPFDocument(inputStream);
//
//        XHTMLOptions options = XHTMLOptions.create();
//        options.indent(4);
//        options.setIgnoreStylesIfUnused(false);
//        options.setFragment(true);
//
//        ByteArrayOutputStream baos = new ByteArrayOutputStream();
//        XHTMLConverter.getInstance().convert(document,baos,options);
//        baos.close();
//        String result = baos.toString();
//
//        String regex = "\\s+\\<\\/span\\>\\s+\\<span style=\"font-size:\\d+\\.\\d+pt;white-space:pre-wrap;\"\\>";
//        result = result.replaceAll(regex, "");
//
//        result = "<html><head><style>p{margin-top:0pt;margin-bottom:1pt;}p.a{text-align:justify;}" +
//                "table.a1{}p, span, div, a {white-space: normal !important;margin-bottom: 15px !important;}" +
//                "body>div{margin: 0 auto  !important;}</style></head><body>" + result + "</body></html>";
//
//        return result;
//    }
//
//    // docx转换为html
//    public static String docToHtml(String url) throws IOException, TransformerException, ParserConfigurationException {
//
//        InputStream inputStream = new URL(url).openStream();
//
//        HWPFDocument wordDocument = new HWPFDocument(inputStream);
//        WordToHtmlConverter converter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
//        //对HWPFDocument进行转换
//        converter.processDocument(wordDocument);
//
//        Writer writer = new StringWriter();
//
//        Transformer transformer = TransformerFactory.newInstance().newTransformer();
//        transformer.setOutputProperty( OutputKeys.ENCODING, "utf-8" );
//        //是否添加空格
//        transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
//        transformer.setOutputProperty( OutputKeys.METHOD, "html" );
//        transformer.transform(
//                new DOMSource(converter.getDocument() ),
//                new StreamResult( writer ) );
//
//        return writer.toString();
//
//    }
//
//
//    public static String docxToTxt(String url) throws IOException, TransformerException, ParserConfigurationException{
//
//        InputStream inputStream = new URL(url).openStream();
//
//        XWPFDocument wordDocument = new XWPFDocument(inputStream);
//        XWPFWordExtractor we = new XWPFWordExtractor(wordDocument);
//
//        String text = we.getText();
//
//        return text;
//    }
//
//    public static String docToTxt(String url) throws IOException, TransformerException, ParserConfigurationException{
//
//        InputStream inputStream = new URL(url).openStream();
//
//        HWPFDocument wordDocument = new HWPFDocument(inputStream);
//        WordToTextConverter converter = new WordToTextConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
//        //对HWPFDocument进行转换
//        converter.processDocument(wordDocument);
//        Writer writer = new StringWriter();
//        Transformer transformer = TransformerFactory.newInstance().newTransformer();
//        transformer.setOutputProperty( OutputKeys.ENCODING, "utf-8" );
//        //是否添加空格
//        transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
//        transformer.setOutputProperty( OutputKeys.METHOD, "text" );
//        transformer.transform(
//                new DOMSource(converter.getDocument() ),
//                new StreamResult( writer ) );
//
//        String text = writer.toString();
//
//        return text;
//    }
//}
